package com.yzx.lifeassistants.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.bean.Lecture;

/**
 * @Description: 讲座报告列表适配器
 * @author: yzx
 * @time: 2016-3-11 下午8:02:51
 */
@SuppressLint("UseSparseArrays")
public class LectureAdapter extends BaseAdapter {

	private List<Lecture> dataList;
	private Lecture data;
	private LayoutInflater inflater;
	private ViewHolder holder;

	// private Animation animation;
	// private Map<Integer, Boolean> isFrist;

	public LectureAdapter(Context context, List<Lecture> dataList) {
		this.dataList = dataList;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		// this.animation = AnimationUtils.loadAnimation(context,
		// R.anim.anim_listview_item);
		// this.isFrist = new HashMap<Integer, Boolean>();
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_lecture_list, parent,
					false);
			holder = new ViewHolder();
			holder.contentTV = (TextView) convertView
					.findViewById(R.id.item_lecture_content_tv);
			holder.dateTV = (TextView) convertView
					.findViewById(R.id.item_lecture_date_tv);
			holder.monthTV = (TextView) convertView
					.findViewById(R.id.item_lecture_month_tv);
			holder.sponsorTV = (TextView) convertView
					.findViewById(R.id.item_lecture_sponsor_tv);
			holder.palceTV = (TextView) convertView
					.findViewById(R.id.item_lecture_palce_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		data = dataList.get(position);
		String beginTime = data.getBeginTime();
		holder.contentTV.setText(data.getContent());
		holder.dateTV
				.setText(beginTime.substring(beginTime.lastIndexOf("-") + 1,
						beginTime.lastIndexOf("-") + 3));
		holder.monthTV.setText(beginTime.substring(0,
				beginTime.lastIndexOf("-")));
		holder.sponsorTV.setText(data.getSponsor());
		holder.palceTV.setText(beginTime.substring(beginTime.indexOf(" ") + 1,
				beginTime.lastIndexOf(":")) + "  " + data.getActivityPlace()

		);
		// // 如果是第一次加载该view，则使用动画
		// if (null == isFrist.get(position)) {
		// convertView.startAnimation(animation);
		// isFrist.put(position, true);
		// }
		return convertView;
	}

	static class ViewHolder {
		TextView contentTV;// 内容
		TextView dateTV;// 日期
		TextView monthTV;// 月份
		TextView sponsorTV;// 主办方
		TextView palceTV;// 举办地点
	}
}
